<?php

declare (strict_types = 1);

namespace app\common\repository\system;

use app\common\model\BaseModel;
use app\common\repository\BaseRepository;
use app\common\model\system\SysConfigGroup;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;

class SysConfigGroupRepository extends BaseRepository
{
    protected \app\common\model\BaseModel $model;

    public function __construct(SysConfigGroup $model)
    {
        $this->model = $model;
    }

    /**
     * 根据分组标识获取配置项
     *
     * @param string $mark 分组标识
     *
     * @return BaseModel|SysConfigGroup|array|Model|null
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getGroupConfigs(string $mark): SysConfigGroup|\app\common\model\BaseModel|array|\think\Model|null
    {
        return $this->model->with(['configs'])->where('mark', $mark)->field('id, name, mark')->find();
    }
}